package com.team.teamproject.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.team.teamproject.R;
import com.team.teamproject.bean.hotitems;

import java.util.List;

/**
 * Created by Administrator on 2016/11/7.
 */

public class firstHotAdapter extends BaseAdapter {
    private List<hotitems>  list;
    private Context context;
    public firstHotAdapter( Context context,List<hotitems>  list){
        this.context=context;
        this.list=list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
            if (convertView==null)
            {
                holder=new ViewHolder();
                convertView= LayoutInflater.from(context).inflate(R.layout.adapter_firsthot,null);
              holder.cv_iv= (ImageView) convertView.findViewById(R.id.cv_iv);
                holder.cv_tv_name= (TextView) convertView.findViewById(R.id.cv_tv_name);
                holder.cv_tv_price= (TextView) convertView.findViewById(R.id.cv_tv_price);
                convertView.setTag(holder);
            }
        else
            {
                holder= (ViewHolder) convertView.getTag();
            }
        hotitems hotitems=list.get(position);

        String cover_image_url=hotitems.getCover_image_url();
        Log.i("abc","---->"+cover_image_url);
        if (cover_image_url!=null)
        {
            Picasso.with(context).load(cover_image_url).into(holder.cv_iv);
        }
        else
        {
            Toast.makeText(context,"错误",Toast.LENGTH_SHORT).show();
        }
        holder.cv_tv_name.setText(hotitems.getName());
        holder.cv_tv_price.setText(hotitems.getPrice());
        return convertView;
    }

   public class ViewHolder{
        ImageView cv_iv;
        TextView cv_tv_name,cv_tv_price;
    }
}
